﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace 学生成绩查询及选课系统
{
    public partial class member_password : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["user"]!=null)
            //{
            //    username.Text = Session["user"].ToString();
            //}
        }

        protected void btn_submit_Click(object sender, EventArgs e)
        {
            string username = Session["user"].ToString() ;

            string sql2 = "select count(*) from dbo.users where username=@username and pwd=@pwd";
            SqlParameter[] arraysql2 = { new SqlParameter("@username", username), new SqlParameter("@pwd",oldPwd.Text) };

            object o = DBAccess.GetOne(sql2, arraysql2);
            if ((int)o != 1)
            {
                tishi.Text = "原密码输入有误";
                return;
            }
            
            if (DBAccess.isNullOrEmpty(oldPwd.Text,newPwd.Text,rePwd.Text))
            {
                tishi.Text = "请填写完整";
                return;
            }
            else if (newPwd.Text != rePwd.Text)
            {
                tishi.Text = "密码不一致";
                return;
            }
            else if (newPwd.Text.Length < 8 || newPwd.Text.Length > 16)
            {
                tishi.Text = "请输入密码长度为8-16位的字符！";
                return;
            }
            else
            {
                tishi.Text = "";
            }
            string sql = "update dbo.users set pwd=@pwd where username=@username";
            SqlParameter[] arraysql = { new SqlParameter("@pwd", newPwd.Text), new SqlParameter("@username", username) };
            int res = DBAccess.GetState(sql, arraysql);
            if (res != 0)
            {
                tishi.Text = "修改成功,请下次登录使用新密码";
                //Response.Redirect("./login.aspx");
            }
            else
            {
                tishi.Text = "修改失败";
            }

        }

        protected void newPwd_TextChanged(object sender, EventArgs e)
        {
            //string username = Session["user"].ToString();
            //string opwd = oldPwd.Text;
            
        }
    }
}